t=int(input())
while t>0:
n=int(input())
a=[]
a=list(map(int,input().split()))
a.sort()
print(a[n-1]+a[n-2]-a[0]-a[1])
t=t-1
#include <iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <numeric>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <unordered_set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
using namespace std;
#define all(a) a.begin(), a.end()
#define cnt0(x) __builtin_ctz(x)
#define endl '\n'
#define itn int
#define ll long long
#define ull unsigned long long
#define rep(i, a, b) for(int i = a;i <= b; i ++)
#define per(i, a, b) for(int i = a;i >= b; i --)
#define cntone(x) __builtin_popcount(x)
#define db double
#define x first
#define y second
#define AC main(void)
#define HYS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<int, int > PII;
typedef pair<int, pair<int, int>> PIII;
typedef pair<ll, ll> Pll;
typedef pair<double, double> PDD;
using ld = double long;
const long double eps = 1e-9;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10, M = 4e5 + 10;
const int INF = 0x3f3f3f3f;
int d1[] = {0, 0, 1, -1};
int d2[] = {1, -1, 0, 0};
int n, m;
int _ = 1;
ll res;
int a[M];
int h[N], ne[M], e[M], idx;
void solve(){
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
sort(a + 1, a + n + 1);
cout << a[n] + a[n - 1] - a[1] - a[2] << endl;
}
int AC{
HYS
cin >> _;
while(_ --)
solve();
return 0;
}
1654C - Alice and the Cake | 369A - Valera and Plates |
1626A - Equidistant Letters | 977D - Divide by three multiply by two |
1654B - Prefix Removals | 1654A - Maximum Cake Tastiness |
1649A - Game | 139A - Petr and Book |
1612A - Distance | 520A - Pangram |
124A - The number of positions | 1041A - Heist |
901A - Hashing Trees | 1283A - Minutes Before the New Year |
1654D - Potion Brewing Class | 1107B - Digital root |
25A - IQ test | 785A - Anton and Polyhedrons |
1542B - Plus and Multiply | 306A - Candies |
1651C - Fault-tolerant Network | 870A - Search for Pretty Integers |
1174A - Ehab Fails to Be Thanos | 1169A - Circle Metro |
780C - Andryusha and Colored Balloons | 1153A - Serval and Bus |
1487C - Minimum Ties | 1136A - Nastya Is Reading a Book |
1353B - Two Arrays And Swaps | 1490E - Accidental Victory |